import React, { PureComponent } from 'react'
import { createPortal } from 'react-dom'
export class App extends PureComponent {
  render() {
    return (
      <div>
        <h2>标题1</h2>
        <h2>标题2</h2>

        {/* createPortal(node, dom) 参数1：要挂载到别的div的react元素节点 参数2：需要挂载到哪个DOM上 */}
        {createPortal(<h3>标题3</h3>, document.querySelector('#second'))}

        <Modal >
          <h2>hahah</h2>
          <h2>hahha</h2>
        </Modal>
      </div>
    )
  }
}
function Modal(props) {
  return (
    <div>
      {createPortal(props.children,document.querySelector('#modal'))}
    </div>
  )
}
export default App